//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.FoxyTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.FoxyRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.FoxyAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.CurtainState    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.FoxyRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.FoxyResumeTimer    // Initially set via a loop in the UFO script

private alias Object.Value9 : Object.DoorTime    // Initially set via a loop in the UFO script
private alias Object.Value10 : Object.HeadShake    // Initially set via a loop in the UFO script
private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script


// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 3 : CAM_PIRATESCOVE_3
private alias 4 : CAM_WESTHALL_4

private alias object.state : Foxy.State



event ObjectMain
//-1 is basically the ai level 0 ig
if Object[5].Type == TypeName[Blank Object]

	switch Foxy.state
	case CAM_WESTHALL_4
	//running
		Object.FoxyTimer++
		if Object.FoxyTimer > 135
			if LeftDoorClosed == 1
				object.state = 15
				PlaySfx(SfxName[Knock], 0)	
				object.FoxyTimer = 0
			else
				StopMusic()
				PlaySfx(SfxName[Jumpscare], 0)		
				object.state = 17
			end if
		end if
	break	
	case 15
	if LeftDoorClosed == 1
		Object.FoxyTimer++
		if Object.FoxyTimer > 150
			object[6].alpha = 355
			object.state = CAM_PIRATESCOVE_3
			Object.CurtainState  = 0
			object.FoxyTimer = 0
		end if
	else	//dont open the door when hes knocking hes still there
		StopMusic()
		StopSfx(SfxName[Knock])
		PlaySfx(SfxName[Jumpscare], 0)	
		object.state = 17					
	end if		
	break
	case 17
		PlayerJumpscared = 1
		if Object.FoxyRise > -100
			Object.FoxyRise -= 16
		else
			Object.FoxyRise = -100
		end if
	break		
	default
		if CameraEnabled == 0
			if Object.FoxyResumeTimer > 0
				Object.FoxyResumeTimer--
			else
				Object.FoxyTimer++
				Object.MoveTime = 500
			//	rand(temp3, 50)
			//	Object.MoveTime += temp3
				if Object.FoxyTimer >= Object.MoveTime 
					Rand(Object.FoxyRandom, 21)
					if Object.FoxyAI > Object.FoxyRandom 
						//these align with the cameras he goes to
						//state 10 is cam 10
						//15+ is at the office watch out

							if Object[6].value1 == Foxy.state
								object[6].alpha = 355
							end if

							switch Foxy.state
							case CAM_PIRATESCOVE_3	//showstage
								switch Object.CurtainState 
								case 0
									Object.CurtainState = 1
								break
								case 1
									Object.CurtainState = 2
								break
								case 2
									Object.CurtainState = 3
								break	
								case 3
									PlaySfx(SfxName[FoxyRun], 0)	
									object[3].frame = 82
									Object[3].scale = 32
									Object.FoxyTimer = 0
									object.state = CAM_WESTHALL_4
								break							
								end switch	
							break
							end switch	

							if Object[6].value1 == Foxy.state
								object[6].alpha = 355
							end if	
							
					end if
					Object.FoxyTimer = 0	
				end if
			end if	
		else
			rand(Object.FoxyResumeTimer, 100)		
		end if	
	break
	end switch
end if	
end event

event ObjectDraw

//	DrawNumbers(0, 32, 96, Object.HeadShake, 3, 8, 0)

//	DrawNumbers(0, 64, 96, Foxy.State, 3, 8, 0)

//	DrawNumbers(0, 96, 96, Object.DoorTime, 3, 8, 0)

	if Object.Tweak == 1
		rand(Object.HeadShake, 6)
	end if	

	if Foxy.state == 17
		object.drawOrder = 5
		if Object.Tweak == 0
			temp0 = screen.xsize
			temp0 -= screen.xsize
			if Object[13].HeadShake < temp0
				Object[13].HeadShake += 20
			else
				Object.Tweak = 1
			end if
		end if	

		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140

		temp2 = temp1
		temp2 += Object.HeadShake	

		DrawSpriteScreenFX(10, FX_SCALE, temp2, Object.FoxyRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp2, Object.FoxyRise)	//head
	end if

	

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[13].Type = TypeName[Foxy]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[13].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[13].DrawOrder = 5

	Object[13].state = CAM_PIRATESCOVE_3

	Object[13].HeadShake = -200

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	SpriteFrame(-30, 230, 290, 118, 204, 1)
	SpriteFrame(48, 120, 202, 191, 1, 1)	//11	

end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
